package code.tools.commponents
{
	import code.structure.manager.loader.DllLoaderManager;
	import code.structure.manager.sound.MySoundManager;
	import code.tools.sound.src.SoundName;
	import code.untils.UiNameConst;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**
	 *关闭按钮 
	 * @author liangqian
	 * 
	 */	
	public class CloseBtn extends Component
	{
		private var closeMc:MovieClip;
		private var _clickFun:Function;
		
		public function CloseBtn(parent:DisplayObjectContainer, xpos:Number, ypos:Number,clickFun:Function)
		{
			_clickFun = clickFun;
			super(parent, xpos, ypos);
			buttonMode = true;
			mouseChildren = false;
			
			closeMc = new (DllLoaderManager.getInstance().getMaterial(UiNameConst.GENERAL_ICON, 'closeBtn') as Class) as MovieClip; 
			closeMc.stop();
			closeMc.mouseChildren = false;
			addChild(closeMc);
			
			addEventListener(MouseEvent.ROLL_OVER,hoverHandler);
			addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		override protected function init():void
		{
			setSize(39,36);
			super.init();
		}
		
		private function hoverHandler(e:MouseEvent):void
		{
			MySoundManager.playSound(SoundName.MOUSE_OVER, 0.2);
			addEventListener(MouseEvent.ROLL_OUT,outHandler);
			closeMc.gotoAndStop(2);
		}
		
		private function outHandler(e:MouseEvent):void
		{
			removeEventListener(MouseEvent.ROLL_OUT,outHandler);
			closeMc.gotoAndStop(1);
		}
		
		private function clickHandler(e:MouseEvent):void
		{
			closeMc.gotoAndStop(3);
			_clickFun();
		}
	}
}